package finder;

import android.graphics.PixelFormat;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import applicationDAO.Institute;

import com.project.trac.R;

import core.modules.AdapterCourse;

public class ActivityManager extends FragmentActivity {

	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_course_manager);
		
		AdapterCourse ca = new AdapterCourse(getApplicationContext(), getSupportFragmentManager());
		ViewPager viewpager = (ViewPager) findViewById(R.id.viewpager_coursemanager);
		
		viewpager.setAdapter(ca);
		viewpager.setCurrentItem(0);

		viewpager.setOnPageChangeListener(new OnPageChangeListener() {

					/* call on the generic_indicators */
					public void onPageSelected(int position) {

						switch (position) {

						case 0:
							findViewById(R.id.generic_tab_first).setVisibility(View.VISIBLE);
							findViewById(R.id.generic_tab_second).setVisibility(View.INVISIBLE);
							break;

						case 1:
							findViewById(R.id.generic_tab_first).setVisibility(View.INVISIBLE);
							findViewById(R.id.generic_tab_second).setVisibility(View.VISIBLE);
							break;
						}
					}
					/* unused methods */
					public void onPageScrollStateChanged(int position) {}
					public void onPageScrolled(int arg0, float arg1, int arg2) {}
				});
		
		
	}
	
	
	@Override
	public void onAttachedToWindow() {
		super.onAttachedToWindow();
		Window window = getWindow();
		window.setFormat(PixelFormat.RGBA_8888);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.menu, menu);
		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
	    switch (item.getItemId()) {
	        case R.id.menu_logout:
	            new Institute().Logout(this);
	            return true;
	        default:
	            return super.onOptionsItemSelected(item);
	    }
	}
	
}